<script src="/assets/style/js/jquery.js"></script>
<style>
.c1{
    font-size: 40px;
    cursor:pointer;
    float: left;
}
.c2{
    font-size: 40px;
    cursor:pointer;
    float: right;
}
.day1{
    width: 700px;
    text-align: center;
    font-size: 30px;
}
.day2{
    width: 1100px;
}
.day21{
    float: left;
    width: 150px;
    color:#ffffff;
    background-color: #32384f;
    text-align: center;
    line-height: 30px;
    font-size: 14px;
    height: 30px;
}
.day3{
    float: left;
    width: 150px;
    border:1px solid #dfdfdf;
    text-align: right;
    height: 80px;
    font-size: 18px;
    color: #32384f;
    background-color: #ffffff;
}
.day30{
    float: left;
    width: 150px;
    border:1px solid #dfdfdf;
    text-align: right;
    height: 80px;
    font-size: 18px;
    color: #32384f;
    background-color: #ffffff;
}
.day301{
    font-size: 12px;
    color: #3b3e4b;
}
.day302{
    font-size: 12px;
    color: #126900;
}
.day303{
    font-size: 12px;
    color: #4f0d00;
}
.day304{
    font-size: 12px;
    color: #ffffff;
    background-color: #1b5958;
}
    .smy{
        font-size: 18px;
    }
   #hgroup{
height: 700px;
       overflow: auto;
    }
.hg1{
    border:1px solid #dfdfdf;
    height: 30px;
    line-height: 30px;
    font-size: 13px;
    color: #32384f;
    background-color: #ffffff;
    text-align: center;
    margin: 1px;
}
    .hg11{
        color: #ffffff;background: #0d1318; position: absolute; width: 180px; height: 220px;
        text-align: left;
        margin-top: 10px;
        border-radius:5px;
        padding-left: 5px;
        z-index: 30;
    }
    .deln1{
        color: #ffffff;background: #0d1318; position: absolute; width: 180px; height: 100px;
        text-align: left;
        margin-top: -120px;
        border-radius:5px;
        padding: 5px;
        padding-top: 15px;
        display: none;
    }
.mask {
    position: absolute; top: 0px; filter: alpha(opacity=90); background-color: #000;
    z-index: 1000; left: 0px;
    opacity:0.9; -moz-opacity:0.9;
}
#addprice{
    padding-top: 20px;
    position: absolute;
    margin-left: 30px;
    display: none;
    background-color: #fff;
    z-index: 1001;
    height: 400px;
    line-height: 40px;
    width: 900px;
    padding-left: 20px;
}
    .ps0{
        width: 100px;
        float:left;
        margin: 5px;
    }
    td{text-align: center;}
    th{background-color: aliceblue; text-align: center}
    .unitprice{
           width: 70px;
       }
    .pricetext{
        width: 300px;
    }
    .input1{
        width: 75px;
    }
    .tableleft{text-align: left;}
    </style>
<div class="content">
<div class="panel panel-default panel-intro">
<div class="panel-body">
<div id="mask" class="mask" onclick="hideMask()"></div>
    <div id="toolbar" class="toolbar">
    </div>
<div style="clear: both"></div>
    <!--生成日历-->
<div class="day0">
    <div class="day1">
        <div class="c1" onclick="show2('p1')"><</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span id="y1"></span>年<span id="m1"></span>月
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <div class="c2" onclick="show2('n1')">></div><div style="clear: both"></div>
        <input type="checkbox" class="smonth" name="smonth" data1="" id="smonth" onchange="st2(this)"/><span class="smy">选择当前全月</span>
       <!-- <input type="checkbox" name="syear" data1="" id="syear" onchange="st2(this)"/><span class="smy">选择当前全年</span>-->
    </div>
    <div class="day2">
        <div class="day21">星期日 <input type="checkbox" checked="false" class="syear" data1="" id="dd0"  onchange="st3(this,'0')"/></div>
        <div class="day21">星期一 <input type="checkbox" checked="false" class="syear" data1="" id="dd1" onchange="st3(this,'1')"/></div>
        <div class="day21">星期二 <input type="checkbox" checked="false" class="syear" data1="" id="dd2" onchange="st3(this,'2')"/></div>
        <div class="day21">星期三 <input type="checkbox" checked="false" class="syear" data1="" id="dd3" onchange="st3(this,'3')"/></div>
        <div class="day21">星期四 <input type="checkbox" checked="false" class="syear" data1="" id="dd4" onchange="st3(this,'4')"/></div>
        <div class="day21">星期五 <input type="checkbox" checked="false" class="syear" data1="" id="dd5" onchange="st3(this,'5')"/></div>
        <div class="day21">星期六 <input type="checkbox" checked="false" class="syear" data1="" id="dd6" onchange="st3(this,'6')"/></div>
    </div>
    <div class="day2" id="day2">
        <div class="day3">1</div>
        <div class="day3">2</div>
        <div class="day3">3</div>
        <div class="day3">4</div>
        <div class="day3">5</div>
        <div class="day3">6</div>
        <div class="day3">7</div>
    </div>
</div>
<div style="clear: both"></div>
<div class="ds1">共选中了<span id="ds1">0</span>天</div>
<div id="ds2"></div>
<a href="/admin/product">返回</a>
<table width="100%">
    <tr>
        <td width="50%" valign="top">
            <form id="add-form"  method="POST" action="/admin/product/group_add">
                <input id="pricestr" type="hidden" name="pricestr" value=""/>
                <input id="glist" type="hidden" name="glist" value=""/>
                <input id="glist1" type="hidden" name="glist1" value=""/>
                <input id="glist2" type="hidden" name="glist2" value=""/>
                <input id="status" type="hidden" name="status" value=""/>
                <input id="action" type="hidden" name="action" value="add"/>
                <input type="hidden" name="p_id" value="{$p_id}">
                <input type="hidden" name="package_id" value="{$package_id}">
                <div class="form-group">
                    全选<input type="checkbox" checked="checked" class="smonth" name="smonth" sd="1" data1="" id="ss2" onchange="sall1(this)"/>
                    <table class="table table-striped">
                        <tbody>
                        <tr>
                            <td><input class="sitem" type="checkbox" name="sele[is_g_max]" value="is_g_max" checked="checked"></td>
                            <td class="tableleft">余位</td>
                            <td class="tableleft">
                                        <input type="text" id="g_max" name="g_max" value="" class="input1" data-rule="" data-tip=""  >
                            </td>
                        </tr>
                        <tr>
                            <td ></td>
                            <td  class="tableleft">已销售</td>
                            <td class="tableleft">
                                        <input type="text"  id="g_number" name="g_number" value="" class="input1" data-rule="" data-tip=""  readonly="readonly">
                            </td>
                        </tr>
                        <tr>
                            <td ><input type="checkbox" class="sitem" name="sele[is_status]" value="is_status" checked="checked"></td>
                            <td  class="tableleft">状态</td>
                            <td class="tableleft">
                                            <input class="saa" type="radio" id="sa1" name="status1" value="0">正常&nbsp;&nbsp;&nbsp;
                                            <input class="saa" type="radio" id="sa2" name="status1" value="1">售罄&nbsp;&nbsp;&nbsp;
                                            <input class="saa" type="radio" id="sa3" name="status1" value="2">下线&nbsp;&nbsp;&nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td><input  type="checkbox" class="sitem" name="sele[is_onehouse]" value="is_onehouse" checked="checked"></td>
                            <td  class="tableleft">单人房差</td>
                            <td class="tableleft">
                                        <input type="text" id="onehouse" name="onehouse" value="" class="input1" data-rule="" data-tip="" id="onehouse">
                            </td>
                        </tr>
                        <tr>
                            <td ><input type="checkbox" class="sitem" name="sele[is_price]" value="is_price" checked="checked"></td>
                            <td  class="tableleft">价格</td>
                            <td class="tableleft">
                                        <div>
                                            <span class=""> 一人单价 </span><input  type="text" id="unitprice1" name="unitprice1" value=""  class="unitprice" data-rule="" data-tip="" oninput="pricetotal(1)">
                                            <span class=""> 总价 </span>
                                            <input  type="text" readonly="readonly" id="totalprice1" name="totalprice1" value=""  class="unitprice" data-rule="" data-tip=""><br/>
                                            <span class=""> 标题 </span>
                                            <input  type="text" id="pricetitle1" name="pricetitle1" value=""  class="pricetext" data-rule="" data-tip=""><br/>
                                            <span class=""> 提示 </span>
                                            <input  type="text" id="priceinfo1" name="priceinfo1" value="单人价包含《单人房差》押金，拼房成功立刻退还"  class="pricetext" data-rule="" data-tip="">
                                        </div>
<br/>
                                        <div>
                                            <span class="pricetext"> 二人单价 </span><input  type="text" id="unitprice2" name="unitprice2" value=""  class="unitprice" data-rule="" data-tip="" oninput="pricetotal(2)">
                                            <span class="pricetext"> 总价 </span>
                                            <input  type="text" readonly="readonly" id="totalprice2" name="totalprice2" value=""  class="unitprice" data-rule="" data-tip=""><br/>
                                            <span class="pricetext"> 标题 </span>
                                            <input  type="text" id="pricetitle2" name="pricetitle2" value=""  class="pricetext" data-rule="" data-tip=""><br/>
                                            <span class="pricetext"> 提示 </span>
                                            <input  type="text" id="priceinfo2" name="priceinfo2" value="两人入住标准双人间大床或双床房"  class="pricetext" data-rule="" data-tip="">
                                        </div>
                                <br/>
                                        <div>
                                            <span class="pricetext"> 三人单价 </span><input  type="text" id="unitprice3" name="unitprice3" value=""  class="unitprice" data-rule="" data-tip="" oninput="pricetotal(3)">
                                            <span class="pricetext"> 总价 </span>
                                            <input  type="text" readonly="readonly" id="totalprice3" name="totalprice3" value=""  class="unitprice" data-rule="" data-tip=""><br/>
                                            <span class="pricetext"> 标题 </span>
                                            <input  type="text" id="pricetitle3" name="pricetitle3" value=""  class="pricetext" data-rule="" data-tip=""><br/>
                                            <span class="pricetext"> 提示 </span>
                                            <input  type="text" id="priceinfo3" name="priceinfo3" value="三人同行入住三人间"  class="pricetext" data-rule="" data-tip="">
                                        </div>
                                <br/>
                                        <div>
                                            <span class="pricetext"> 四人单价 </span><input  type="text" id="unitprice4" name="unitprice4" value=""  class="unitprice" data-rule="" data-tip="" oninput="pricetotal(4)">
                                            <span class="pricetext"> 总价 </span>
                                            <input  type="text" readonly="readonly" id="totalprice4" name="totalprice4" value=""  class="unitprice" data-rule="" data-tip=""><br/>
                                            <span class="pricetext"> 标题 </span>
                                            <input  type="text" id="pricetitle4" name="pricetitle4" value=""  class="pricetext" data-rule="" data-tip=""><br/>
                                            <span class="pricetext"> 提示 </span>
                                            <input  type="text" id="priceinfo4" name="priceinfo4" value=""  class="pricetext" data-rule="" data-tip="">
                                        </div>
                            </td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" class="sitem" name="sele[is_discount]" value="is_discount" checked="checked"></td>
                            <td  class="tableleft">折扣</td>
                            <td class="tableleft">
                                        <input type="text" id="discount" name="discount" value="" class="input1" data-rule="" data-tip="" id="discount">
                                        扣去的折扣
                            </td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" class="sitem" name="sele[is_selfpayid]" value="is_selfpayid" checked="checked"></td>
                            <td  class="tableleft">选择自费项目</td>
                            <td class="tableleft">
                                        <select name="selfpayid" id="selfpayid">
                                            <option value="">无自费项目</option>
                                            {volist name="selfpaylist" id="selfpaylist"}
                                            <option value="{$selfpaylist.id}">{$selfpaylist.title}</option>
                                            {/volist}
                                        </select>
                            </td>
                        </tr>
                        <tr>
                            <td ><input type="checkbox" class="sitem" name="sele[is_childrenprice]" value="is_childrenprice" checked="checked"></td>
                            <td class="tableleft">儿童单价</td>
                            <td class="tableleft">
                                        <input type="text" id="childrenprice" name="childrenprice" value="" class="input1" data-rule="" data-tip="" id="childrenprice">
                            </td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" class="sitem" name="sele[is_industry_share]" value="is_industry_share" checked="checked"></td>
                            <td  class="tableleft">同业是否享受折扣</td>
                            <td class="tableleft">
                                        <input type="radio" id="ins0" name="industry_share" value="0" checked="">
                                        同业享受折扣
                                        <input type="radio" id="ins1" name="industry_share" value="1">
                                        同业不享受折扣
                            </td>
                        </tr>
                        <tr>
                            <td ><input type="checkbox" class="sitem" name="sele[is_discounttype]" value="is_discounttype" checked="checked"></td>
                            <td  class="tableleft">同业佣金类型</td>
                            <td>
                                        <input type="radio" id="dis0" name="discounttype" value="0" checked="">
                                        早鸟
                                        <input type="radio" id="dis1" name="discounttype" value="1">
                                        闪电
                            </td>
                        </tr>
                        </tbody>
                        <tfoot>
                        <tr>
                            <td></td>
                            <td></td>
                            <td>
                                <div class="deln1">
                                    <p align="center">是否删除<span id="delid"></span>个团期？</p>
                                    <p align="center">
                                        <button type="button" onclick="del()" class="btn btn-success btn-embossed">确定</button>
                                        <button type="reset" onclick="caneldel()" class="btn btn-default btn-embossed">取消</button>
                                    </p>
                                </div>
                                <button type="button" class="btn btn-success btn-embossed" onclick="addchangesub()">添加修改</button>
                                <button type="button" class="btn btn-success btn-embossed" onclick="del1()">删除所选团期</button>
                                <button type="button" class="btn btn-success btn-embossed">返回</button>
                                <button type="reset" onclick="reset1()" class="btn btn-default btn-embossed">重置</button>
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </form>
        </td>
        <td width="50%" valign="top">
全选<input type="checkbox" class="smonth" name="smonth" sd="0" data1="" id="ss1" onchange="sall(this)"/>
            <div id="hgroup">
                <table  class="table table-striped">
                    <tr>
                        <th>日期</th>
                        <th>余位</th>
                        <th>已销售</th>
                        <th>状态</th>
                        <th>价格</th>
                        <th>折扣</th>
                        <th>单人房差</th>
                        <td>佣金类型</td>
                    </tr>
                    {foreach name="list" item="vo"}
                    <tr class="hg1"  onclick="hgs(this)" sd="0" data0="{$vo['id']}" data1="<?php echo date('Y-m-d',$vo['g_time'])?>" data2="{$vo['status']}" data3="{$vo['price']}" data4="{$vo['discount']}" data5="{$vo['childrenprice']}" data6="{$vo['onehouse']}" data7="{$vo['discounttype']}" data8="{$vo['g_max']}" data9="{$vo['pricelist']}" data10="{$vo['g_number']}">
                        <td><?php echo date("Y-m-d",$vo['g_time'])?></td>
                        <td>{$vo['g_max']} </td>
                        <td>{$vo['g_number']}</td>
                        <td>{$vo['status']}</td>
                        <td>{$vo['price']} </td>
                        <td>{$vo['discount']}</td>
                        <td>{$vo['onehouse']}</td>
                        <td>
                            <?php echo getstr("product_group-discounttype",$vo['discounttype'])?></td>
    </tr>
    {/foreach}
                </table>
            </div>
        </td>
    </tr>
</table>
</div>
</div>
</div>
<script language="JavaScript">
   // 删除指定下标数组元素
    Array.prototype.del=function(index){
        if(isNaN(index)||index>=this.length){
            return false;
        }
        for(var i=0,n=0;i<this.length;i++){
            if(this[i]!=this[index]){
                this[n++]=this[i];
            }
        }
        this.length-=1;
    };
   /// 删除指定元素
    Array.prototype.indexOf = function(val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };
    Array.prototype.remove = function(val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };
   function descend(x,y){
       return   x[0]-y[0];  //按照数组的第1个值升序排列
   }
  function  pricetotal(pricenum){
      $("#totalprice"+pricenum).val($("#unitprice"+pricenum).val()*pricenum);
  }
//添加修改按钮提交
   function addchangesub(){
       plstr="";
for(var i=1;i<5;i++){
    if($("#unitprice"+i).val()!=""){
        plstr1=i+"#"+$("#unitprice"+i).val()+"#"+$("#pricetitle"+i).val()+"#"+$("#priceinfo"+i).val()
        plstr=plstr+plstr1+"@";
    }
}
       plstr=plstr.substring(0,plstr.length-1);
        if(plstr==""){
           alert("请输入价格！");
           return;
       }
       $("#pricestr").val(plstr);
       console.log(plstr);
       var g_max=$("#g_max").val();
       if(g_max==""){
           $("#g_max").val("99");
       }
       $("#add-form").submit();
   }
    //定义当前显示的图层
    var hdiv="";
    //显示遮罩层
    function showMask(){
        $("#mask").css("height",$(document).height());
        $("#mask").css("width",$(document).width());
        $("#mask").show();
        $("#mask").css({opacity:'0'});
        $("#mask").animate({opacity:'0.8'},"fast");
    }
    //隐藏遮罩层
    function hideMask(){
        $("#mask").css({opacity:'0.8'});
        $("#mask").animate({opacity:'0'},"fast",function(){
            $("#mask").hide();
            //需要同时隐藏的div
            $("#"+hdiv).hide();
        });
    }
    //
    function pricea(){
     //取值
        hideMask()
        var tid=$("#tid").val();
        var pnum1=$("#pnum1").val();
        var price1=$("#price1").val();
        var title1=$("#title1").val();
        var info1=$("#info1").val();
        var plstr=$("#pricestr").val();
        //补全字段
        if(pnum1=="1"&&title1==""){
            title1="1人";
        }
        if(pnum1=="1"&&info1==""){
            if($("#onehouse").val()==""){
                alert("请先输入单人房差，若没有请输入0")
                retrun;
            }
            info1="单人价包含"+$("#onehouse").val()+"欧元《单人房差》押金，拼房成功立刻退还";
        }
        if(pnum1=="2"&&title1==""){
            title1="2人";
        }
        if(pnum1=="2"&&info1==""){
            info1="两人入住标准双人间大床或双床房";
        }
        if(pnum1=="3"&&title1==""){
            title1="3人";
        }
        if(pnum1=="3"&&info1==""){
            info1="三人同行入住三人间";
        }
        //tid为空是新增，tid不为空是修改
        if(tid==""){
            if(plstr==""){
                plstr=pnum1+"#"+price1+"#"+title1+"#"+info1
            }else{
                plstr=plstr+"@"+pnum1+"#"+price1+"#"+title1+"#"+info1
            }
        }else{
            var n1str=pnum1+"#"+price1+"#"+title1+"#"+info1;
            var  plarr=plstr.split('@');
           for(var i=0;i<plarr.length;i++){
               if(i==tid){
                   plarr[i]= n1str;
               }
           }
            plstr=plarr.join("@");
        }
        //排序
        var plarr=plstr.split('@')
           for(var i=0;i<plarr.length;i++){
               var plarr1=plarr[i].split('#')
               plarr[i]=plarr1;
           }
        plarr.sort(descend);
        for(var i=0;i<plarr.length;i++){
            var plstr1=plarr[i].join('#')
            plarr[i]=plstr1;
        }
        plstr=plarr.join("@");
        $("#pricestr").val(plstr);
        plshow()
    }
//根据全局变量plstr，构造页面显示内容
    function plshow() {
        var plarr = new Array()
        var plstr = $("#pricestr").val();
        if (plstr != "") {
            plarr = plstr.split('@');
        }
        for (var i = 1; i < 5; i++) {
            $("#unitprice" + i).val();
            $("#totalprice" + i).val();
            $("#pricetitle" + i).val();
            $("#priceinfo" + i).val();
        }
        for (var i = 0; i < plarr.length; i++) {
            var plarr1 = plarr[i].split("#");
            $("#unitprice" + plarr1[0]).val(plarr1[1]);
            $("#totalprice" + plarr1[0]).val(Math.round(plarr1[1] * plarr1[0]));
            $("#pricetitle" + plarr1[0]).val(plarr1[2]);
            $("#priceinfo" + plarr1[0]).val(plarr1[3]);
        }
    }
   //删除价格
   function pricedel(tid){
       var plstr=$("#pricestr").val();
       var  plarr=plstr.split('@');
       var outhtml=""
       plarr.del(tid);
       plstr=plarr.join('@');
       $("#pricestr").val(plstr);
       plshow();
   }
//显示价格增加修改图层
function priceadd(tid,pnum1,price1,title1,info1){
    showMask();
    $("#addprice").css("display","block")
    $("#addprice").css("top",(document.documentElement.scrollTop+100)+"px");
    $("#tid").val(tid);
    $("#pnum1").val(pnum1);
    $("#price1").val(price1);
    $("#title1").val(title1);
    $("#info1").val(info1);
    hdiv="addprice";
}
    //构造已有团期数组
    $pg1=new Array();
    $(".hg1").each(function(){
        $pg11=new Array();
        $pg11[0]=$(this).attr("data0")
        $pg11[1]=$(this).attr("data1")
        $pg11[2]=$(this).attr("data2")
        $pg11[3]=$(this).attr("data3")
        $pg11[4]=$(this).attr("data4")
        $pg11[5]=$(this).attr("data5")
        $pg11[6]=$(this).attr("data6")
        $pg11[7]=$(this).attr("data7")
        $pg11[8]=$(this).attr("data8")
        $pg1[$pg1.length]=$pg11;
    })
    //被选择的日期数组-需要修改数据 id数组
    var newd1=new Array();
    //被选择的日期数组-需要增加数据 年-月-日
    var newd2=new Array();
    //被选择的日期数组 年-月-日
    var seld=new Array();
    //被选择的星期数组 年-月-周
    var seld1=new Array();
    //被选择的月份数组 年-月
    var seld2=new Array();
    //被选择的年份数组 年
    var seld3=new Array();
    var color1="";
    var date=new Date;
    var year1=date.getFullYear();
    var month1=date.getMonth()+1;
    month1 =(month1<10 ? "0"+month1:month1);
        /*JQuery 限制文本框只能输入数字*/
        $("#sa5").keyup(function(){
            $(this).val($(this).val().replace(/[^\d]/g,''));
        }).bind("paste",function(){  //CTR+V事件处理
            $(this).val($(this).val().replace(/[^\d]/g,''));
        }).css("ime-mode", "disabled"); //CSS设置输入法不可用
    $("#discount").keyup(function(){
        $(this).val($(this).val().replace(/[^\d]/g,''));
    }).bind("paste",function(){  //CTR+V事件处理
        $(this).val($(this).val().replace(/[^\d]/g,''));
    }).css("ime-mode", "disabled"); //CSS设置输入法不可用
    $("#g_max").keyup(function(){
        $(this).val($(this).val().replace(/[^\d]/g,''));
    }).bind("paste",function(){  //CTR+V事件处理
        $(this).val($(this).val().replace(/[^\d]/g,''));
    }).css("ime-mode", "disabled"); //CSS设置输入法不可用
        /*JQuery 限制文本框只能输入数字和小数点*/
        $("#onehouse").keyup(function(){
            $(this).val($(this).val().replace(/[^0-9.]/g,''));
        }).bind("paste",function(){  //CTR+V事件处理
            $(this).val($(this).val().replace(/[^0-9.]/g,''));
        }).css("ime-mode", "disabled"); //CSS设置输入法不可用
//删除操作
function del(){
    $("#action").val("del");
    $("#add-form").submit();
}
    //取消删除操作
    function caneldel(){
        $(".deln1").css("display","none")
    }
function del1(){
$(".deln1").css("display","block")
$("#delid").html(newd1.length);
$("#delinfo").html($("#glist2").val())
}
    $(document).ready(function () {
        $("#y1").html(year1);
        $("#m1").html(month1);
        show1(year1,month1)
        //
        $(".hg1").find(".hg11").toggle()
        $(".hg1").hover(function() {
            $(this).find(".hg11").toggle();
        }, function() {
            $(this).find(".hg11").toggle();
        });
        $('input[type=radio][name=status1]').change(function() {
            $("#sa5").val("");
            $("#status").attr("value",this.value);
        });
    })
//js输出状态值
    function getgstatus1(st1){
        if(st1==0){
            return "正常";
        }
        if(st1==1){
            return "售罄";
        }
        if (st1==2){
            return "下线";
        }
    }
    /*获取上个月*/
    function getPreMonth(date) {
        var arr = date.split('-');
        var year = arr[0]; //获取当前日期的年份
        var month = arr[1]; //获取当前日期的月份
        var day = arr[2]; //获取当前日期的日
        var days = new Date(year, month, 0);
        days = days.getDate(); //获取当前日期中月的天数
        var year2 = year;
        var month2 = parseInt(month) - 1;
        if (month2 == 0) {
            year2 = parseInt(year2) - 1;
            month2 = 12;
        }
        var day2 = day;
        var days2 = new Date(year2, month2, 0);
        days2 = days2.getDate();
        if (day2 > days2) {
            day2 = days2;
        }
        if (month2 < 10) {
            month2 = '0' + month2;
        }
        var t2 = year2 + '-' + month2 + '-' + day2;
        return t2;
    }
    /*获取下个月*/
    function getNextMonth(date) {
        var arr = date.split('-');
        var year = arr[0]; //获取当前日期的年份
        var month = arr[1]; //获取当前日期的月份
        var day = arr[2]; //获取当前日期的日
        var days = new Date(year, month, 0);
        days = days.getDate(); //获取当前日期中的月的天数
        var year2 = year;
        var month2 = parseInt(month) + 1;
        if (month2 == 13) {
            year2 = parseInt(year2) + 1;
            month2 = 1;
        }
        var day2 = day;
        var days2 = new Date(year2, month2, 0);
        days2 = days2.getDate();
        if (day2 > days2) {
            day2 = days2;
        }
        if (month2 < 10) {
            month2 = '0' + month2;
        }
        var t2 = year2 + '-' + month2 + '-' + day2;
        return t2;
    }
    //根据年月 获取当月天数
    function getMonthDays(year,month){
        var thisDate = new Date(year,month,0); //当天数为0 js自动处理为上一月的最后一天
        return thisDate.getDate();
    }
    //根据年月，形成当月日历数组
    function mouthdate(year,month){
        var moutharray= new Array();
        //获取当月天数
        var mdays=  getMonthDays(year,month)
        //获取当月1日是星期几，用于判断数组前需要添加几个空记录
        var d1=year+"-"+month+"-1";
        var d11=  new Date(d1).getDay()
        //获取当月最后是星期几，用于判断数组后需要添加几个空记录
        var d2=year+"-"+month+"-"+mdays;
        var d21=  new Date(d2).getDay()
        for(var i=0;i<d11;i++){
            var mlist=new Array();
            mlist[0]="";
            moutharray[moutharray.length]=mlist;
        }
        for(var i=1;i<mdays+1;i++){
            var mlist=new Array();
            mlist[0]=i;
            moutharray[moutharray.length]=mlist;
        }
        for(var i=0;i<(6-d21);i++){
             var mlist=new Array();
            mlist[0]="";
             moutharray[moutharray.length]=mlist;
        }
        return moutharray;
    }
//拼装日历
function show1(year,month){
    var darr= mouthdate(year,month)
    var out1="";
    for(var i=0;i<darr.length;i++){
        var   ss="";
        if(darr[i][0]==""){
            out1=out1+"<div class='day30'>&nbsp;</div>"
        }else{
            var   sd =(darr[i][0]<10 ? "0"+darr[i][0]:darr[i][0]);
               ss=year1+"-"+month1+"-"+sd
            var   sd1=new Date(ss).getDay()
            var   sd2=0;
            var   sdsty="";
            var   s1=0;
            if(seld.indexOf(ss)==-1){
                sd2=0
                sdsty=""
            }else{
                sd2=1
                sdsty="background-color:#e9e9e9"
            }
            var ot1=darr[i][0];
            for(var j=0;j<$pg1.length;j++){
                if($pg1[j][1]==ss){
                    s1=$pg1[j][0];
                    //构造余位
                    var remain="<span>余:"+$pg1[j][8]+"</span>";
                    if($pg1[j][8]<4){
                        remain="<span style='color: #ff5500'>余:"+$pg1[j][8]+"</span>";
                    }
                    //构造折扣
                    var discount=""
                    if($pg1[j][4]==0){
                        discount="<span style='color: #000000'>折:"+$pg1[j][4]+"</span>";
                    }else{
                        discount="<span style='color: #990085'>折:"+$pg1[j][4]+"</span>";
                    }
                    //构造状态
                    var status="";
                    if($pg1[j][2]==0){
                         status="<span style='color: #089b00'>"+getgstatus1($pg1[j][2])+"</span>";      }
                    if($pg1[j][2]==1) {
                         status = "<span style='color:#ff0000'>" + getgstatus1($pg1[j][2]) + "</span>";
                    }
                    if($pg1[j][2]==2){
                             status="<span style='color: #ff6600'>"+getgstatus1($pg1[j][2])+"</span>";}
                            ot1 =ot1+"<div class='day301'>"+remain+"，"+discount+"，"+status+"</div>"+"<div class='day302'>"+$pg1[j][3]+"</div>"+"<div class='day303'></div>"
                }
            }
            out1=out1+"<div s1='"+s1+"'  sd='"+sd2+"' style='"+sdsty+"' class='day3' data1='"+ss+"' data2='"+sd1+"'>"+ot1+"</div>"
        }
    }
    $("#day2").animate({opacity:'0'},10,function(){
        $("#day2").html(out1)
        day3c();
    });
    $("#day2").animate({opacity:'1'},10);
    // 设置 全选 年月周的选中状态  判断 全选 年月周的选中状态
    $("#syear").attr("data1",year1)
    $("#smonth").attr("data1",year1+"-"+month1)
    for(var i=0;i<7;i++){
        $("#dd"+i).attr("data1",year1+"-"+month1+"-"+i);
    }
/**
if(seld3.indexOf(year1)!=-1){
    $("#syear").prop("checked", true);
}else{
    $("#syear").prop("checked", false);
}
if(seld2.indexOf(year1+"-"+month1)!=-1){
        $("#smonth").prop("checked", true);
    }else{
    $("#smonth").prop("checked", false);
}
    for(var i=0;i<7;i++){
        if(seld1.indexOf(year1+"-"+month1+"-"+i)!=-1){
            $("#dd"+i).prop("checked", true);
        }else{
            $("#dd"+i).prop("checked", false);
        }
    }
**/
}
    //全选年
    function st1(obj){
        if ($(obj).prop("checked")){
           alert("选中")
        }else{
            alert("未选中")
        }
    }
    //全选月
    function st2(obj){
        if ($(obj).prop("checked")){
            //月数据加入月数组
            if(seld2.indexOf($(obj).attr("data1"))==-1){
                seld2[seld2.length]=$(obj).attr("data1");
            }
            $(".day3").each(function(){
                //天数据加入天数组
                selectday(this,0)
                $(this).attr("sd","1")
                $(this).css("backgroundColor","#e9e9e9")
            })
        }else{
            //月数组删除月数据
            seld2.remove($(obj).attr("data1"))
            $(".day3").each(function(){
                selectday(this,1)
                $(this).attr("sd","0")
                $(this).css("backgroundColor","#ffffff")
            })
        }
        //全选完成后统计数据
        sdata();
    }
    //全选周
    function st3(obj,dn){
        if ($(obj).prop("checked")){
            //周数据加入周数组
           if(seld1.indexOf($(obj).attr("data1"))==-1){
               seld1[seld1.length]=$(obj).attr("data1");
               console.log(seld1);
           }
            $(".day3").each(function(){
                if($(this).attr("data2")==dn){
                    //天数据加入天数组
                    selectday(this,0)
                    $(this).css("backgroundColor","#e9e9e9")
                    $(this).attr("sd","1")
                }
            })
        }else{
            //周数组删除周数据
            seld1.remove($(obj).attr("data1"))
            $(".day3").each(function(){
                if($(this).attr("data2")==dn){
                    selectday(this,1)
                    $(this).css("backgroundColor","#ffffff")
                    $(this).attr("sd","0")
                }
            })
        }
        //全选完成后统计数据
        sdata();
    }
    //日期单次点击
    function day3c(){
        $(".day3").click(function(){
            if($(this).attr("sd")==0){
                selectday(this,0)
                $(this).css("backgroundColor","#e9e9e9")
                $(this).attr("sd","1")
            }else{
                selectday(this,1)
                $(this).css("backgroundColor","#ffffff")
                $(this).attr("sd","0")
            }
            //选择完成后展示统计数据
            sdata();
        });
    }
    //点击上月，下月
    function show2(ax){
        var cd1=year1.toString()+"-"+month1.toString()+"-"+"01";
        if(ax=='p1'){
            var ged= getPreMonth(cd1)
            var arr = ged.split('-');
            year1 = arr[0]; //获取上月的年份
            month1 = arr[1]; //获取上月的月份
            $("#y1").html(year1);
            $("#m1").html(month1);
            show1(year1,month1)
        }
        if(ax=="n1"){
            var ged= getNextMonth(cd1)
            var arr = ged.split('-');
            year1 = arr[0]; //获取下月的年份
            month1 = arr[1]; //获取下月的月份
            $("#y1").html(year1);
            $("#m1").html(month1);
            show1(year1,month1)
        }
    }
     //所有选择完成后，数据拼接，页面显示已选日期
    function sdata(){
        $("#ds1").html(seld.length);
        //拼接主数组
        var ot1="";
        for(var i=0;i<seld.length;i++){
            ot1=ot1+"|"+seld[i];
        }
        //拼接新增数组
        var ot2="";
        for(var i=0;i<newd2.length;i++){
            ot2=ot2+"|"+newd2[i];
        }
        //拼接修改数组
        var ot3="";
        for(var i=0;i<newd1.length;i++){
            ot3=ot3+"|"+newd1[i];
        }
        //根据修改数组最后一个数据，封装数据到表单
        $(".hg1").each(function(){
            if($(this).attr("data0")==newd1[newd1.length-1]){
                $("#g_max").val($(this).attr("data8"));
                $("#price").val($(this).attr("data3"));
                $("#discount").val($(this).attr("data4"));
                $("#childrenprice").val($(this).attr("data5"));
                $("#onehouse").val($(this).attr("data6"));
                $("#pricestr").val($(this).attr("data9"));
                plshow()
                //闪电促销判断默认选项
                if($(this).attr("data7")=="0"){
                    $("#dis0").prop("checked")
                }
                if($(this).attr("data7")=="1"){
                    $("#dis1").prop("checked")
                }
                //状态选项
                if($(this).attr("data2")=="0"){
                    $("#sa1").prop("checked",true);
                }
                if($(this).attr("data2")=="1"){
                    $("#sa2").prop("checked",true);
                }
                if($(this).attr("data2")=="2"){
                    $("#sa3").prop("checked",true);
                }
            }
        })
        $("#ds2").html(ot1);
        $("#glist").attr("value",ot1);
        $("#glist1").attr("value",ot2);
        $("#glist2").attr("value",ot3);
    }
    //全选所有已有团期
   function sall(obj){
       if($(obj).attr("sd")==0){
           $(obj).attr("sd",1)
           $(".hg1").each(function (){
             if($(this).attr("sd")==0){
                 hgs($(this))
             }
           })
       }else{
           $(obj).attr("sd",0)
           $(".hg1").each(function (){
               if($(this).attr("sd")==1){
                   hgs($(this))
               }
           })
       }
   }
function sall1(obj){
    if($(obj).attr("sd")==0) {
        $(obj).attr("sd", 1)
        $(".sitem").prop("checked",true);
    }else{
        $(obj).attr("sd", 0)
        $(".sitem").prop("checked",false);
    }
}
    // 原有团期日期点击
    function hgs(obj){
        if($(obj).attr("sd")==0){
            $(obj).css("backgroundColor","#e9e9e9")
            seld[seld.length]=$(obj).attr("data1");
            newd1[newd1.length]=$(obj).attr("data0")
            $(obj).attr("sd","1");
            //判断当前页是否有选中状态
            $(".day3").each(function(){
                   if($(this).attr("data1")==$(obj).attr("data1")){
                       $(this).attr("sd","1")
                       $(this).css("backgroundColor","#e9e9e9")
                   }
            })
        }else{
            $(obj).css("backgroundColor","#ffffff")
            seld.remove($(obj).attr("data1"))
            newd1.remove($(obj).attr("data0"))
            $(obj).attr("sd","0");
            //判断当前页是否有选中状态
            $(".day3").each(function(){
                if($(this).attr("data1")==$(obj).attr("data1")){
                    $(this).attr("sd","0")
                    $(this).css("backgroundColor","#ffffff")
                }
            })
        }
        sdata()
    }
//日历中选中某个日期（包括月选，周选，单选）后进行数据封装， obj--选择的对象   st1---选中状态
function selectday(obj,st1){
        if(st1==0){
            //加入主数组
            if(seld.indexOf($(obj).attr("data1"))==-1){
                seld[seld.length]=$(obj).attr("data1");
            }
            //判断是否原有数据
            if($(obj).attr("s1")==0){
                //加入新增数组
                if(newd2.indexOf($(obj).attr("data1"))==-1){
                    newd2[newd2.length]=$(obj).attr("data1");
                }
            }else{
                //加入修改数组
                if(newd1.indexOf($(obj).attr("s1"))==-1){
                    newd1[newd1.length]=$(obj).attr("s1");
                }
                //修改已有数据状态
                $(".hg1").each(function(){
                   if($(this).attr("data0")==$(obj).attr("s1")){
                       $(this).attr("sd","1");
                       $(this).css("backgroundColor","#e9e9e9")
                   }
                })
            }
        }else{
            //从主数组中删除
            seld.remove($(obj).attr("data1"))
            if($(obj).attr("s1")==0){
                //从新增数组中删除
                newd2.remove($(obj).attr("data1"))
            }else{
                //从修改数组中删除
                newd1.remove($(obj).attr("s1"))
                //修改已有数据状态
                $(".hg1").each(function(){
                    if($(this).attr("data0")==$(obj).attr("s1")){
                        $(this).attr("sd","0");
                        $(this).css("backgroundColor","#ffffff")
                    }
                })
            }
        }
}
    //点击重置按钮
function reset1(){
    $("#glist").val("");
    $("#glist1").val("");
    $("#glist2").val("");
    //被选择的日期数组-需要修改数据 id数组
     newd1=new Array();
    //被选择的日期数组-需要增加数据 年-月-日
    newd2=new Array();
    //被选择的日期数组 年-月-日
    seld=new Array();
    //被选择的星期数组 年-月-周
     seld1=new Array();
    //被选择的月份数组 年-月
    seld2=new Array();
    //被选择的年份数组 年
    seld3=new Array();
    $(".day3").css("backgroundColor","#ffffff")
    $(".day3").attr("sd","0")
    $(".hg1").css("backgroundColor","#ffffff")
    $(".hg1").attr("sd","0")
    $(".syear").attr("checked",false);
    $(".smonth").attr("checked",false);
    sdata()
}
    </script>
